package cheme.ProcessEditor.Parts.Streams.Tag;

import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gef.editpolicies.ComponentEditPolicy;

import cheme.ProcessEditor.Tools.CreateAfterRequest;
import cheme.ProcessModel.Cmds.AddCmd;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.Tag;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.TagComponent;
import cheme.ProcessModel.ProcessUnits.Streams.Tags.TagComponentList;

public class PolicyTag extends ComponentEditPolicy
{
	@Override
	public Command getCommand(Request request)
	{
		if(request instanceof CreateAfterRequest)
		{
			return getAddStreamDescriptorCmd((CreateAfterRequest)request);
		}

		return super.getCommand(request);
	}
	
	public Command getAddStreamDescriptorCmd(CreateAfterRequest request)
	{
		CompoundCommand cmd = new CompoundCommand();
		
		 /*
		  * Potenitially chain a command to crewate the initial list.
		  */
		
		Tag tag = (Tag)getHost().getModel();
		TagComponentList parent = tag.getTagComponentList(); 
		
//		if(null == parent)
//		{
//			parent = new TagComponentList(tag);
//			cmd.add(new AddCmd(parent, tag, Tag.LIST_INDEX));
//		}
		
		cmd.add(new AddCmd(new TagComponent(parent), parent));
				
		return cmd.unwrap();
	}
}
